package com.sale.succ.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;

import com.sale.succ.system.TradeMarketException;

public final class TraderHelper {
	private static String currentDir;

	private TraderHelper() {

	}

	public static String getLabel(String key) {
		return ProjectBundle.getValue(SystemConstants.BUNDLE_LABEL_PATH, key);
	}

	public static String getCurrentDir() {
		if (currentDir == null) {
			String pathToEve = System.getProperty(SystemConstants.PATH_TO_EVE);
			File file = new File(pathToEve);
			currentDir = file.getParentFile().toString();
		}
		return currentDir;
	}

	public static void saveSystemProps(Properties props) {
		try {
			FileOutputStream out = new FileOutputStream(SystemConstants.SYS_FILE);
			props.store(out, "Created with gui");
			out.close();
		} catch (Exception e) {
			new TradeMarketException(e.getMessage(), "Cannot save Sys props");
		}
	}
	
	public static String convertToKey(String s1, String s2){
		return s1 + "_" + s2;
	}

	public static Properties getSystemProps() {
		Properties prop = new Properties();
		try {
			File file = new File(SystemConstants.SYS_FILE);
			if(!file.exists()){
				file.createNewFile();
			}
			FileInputStream in = new FileInputStream(file);
			prop.load(in);
			in.close();
		} catch (Exception e) {
			new TradeMarketException(e.getMessage(), "Cannot load Sys Props");
		}
		return prop;
	}
}
